<?php
/**
 * Created by PhpStorm.
 * User: j28981
 * Date: 2015/8/29
 * Time: 15:19
 * 将查询出的数据列表缓存在文件
 *
 */
class Cache{
    //private $query_list;    //数据库查询出的数组
    private $file_path;     //缓存文件位置
    private $file_dir;
   // private $query_list_serial; //数组序列化为字符串
   // private $file_name;
    public function __construct($file_name){
        //$this->query_list_serial = serialize($query_list);
        $this->file_dir = $GLOBALS['config']['cache']['file_dir_list'];
        $this->file_path = $this->file_dir.DS.$file_name;
     //  return  $this->cacheFileExists();
    }
    public function CacheWrite($query_list) {
        if(!is_dir($this->file_dir)){
            mkdir($this->file_dir);
        }
        $query_list_serial = serialize($query_list);
        file_put_contents($this->file_path,$query_list_serial);
    }
    public function CacheRead(){
        $str = file_get_contents($this->file_path);
        $list = unserialize($str);
        return $list;
    }
    public function cacheFileExists(){
        if(is_file($this->file_path)){
            return true;
        }else{
            return false;
        }
    }
}